<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        fixed
        prop="userId"
        label="学号">
      </el-table-column>
      <el-table-column
        prop="college"
        label="学院">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="username"
        label="账号">
      </el-table-column>

      <el-table-column
        fixed="right"
        label="操作"
        align="center">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit-outline" size="small">修改</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  created:function (){
    const _this = this;
    axios.get('http://localhost:1234/findUser/'+ this.Global.userId +'').then(function (resp){
      console.log(resp);
      _this.tableData = resp.data;
    })
  },
  watch:{
    $route(to,from){
      if(to.path=="/personal"){
        const _this = this;
        axios.get('http://localhost:1234/findUser/'+ this.Global.userId +'').then(function (resp){
          _this.tableData = resp.data;
        })
      }
    }
  },
  methods: {
    edit(row) {
      console.log(row);
      let arr = JSON.stringify(row);
      this.$router.push({
        path: '/updateOneself',
        query:{
          row: encodeURIComponent(arr)
        }
      })
    }
  },
  data() {
    return {
      tableData: null,
      value: true,
    }
  },
}
</script>
